package com.onion.plugin.spring.listener;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

import java.lang.annotation.Annotation;
import java.util.Map;

public class SpringContext implements ApplicationContextAware {

    private static ApplicationContext context;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.context = applicationContext;
    }

    public static <T> T getBean(String beanId, Class<T> clazz){
        return context.getBean(beanId, clazz);
    }

    public static <T> Map<String, T> getBeansOfType(Class<T> clazz){
        return context.getBeansOfType(clazz);
    }

    public static Map<String, Object> getBeansOfAnnotation(Class<? extends Annotation> annotation){
        return context.getBeansWithAnnotation(annotation);
    }

}